package com.cetc.stream;

import com.cetc.lambda.Person;
import org.junit.Test;

import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @Classname StreamTest03
 * @Description map映射测试
 * @Date 2023/1/5 21:36
 * @Created by louzhuangxi
 */
public class StreamTest03 {
    List<Person> personList = Arrays.asList(
            new Person("张三", 24),
            new Person("李四", 80),
            new Person("王五", 28),
            new Person("赵六2", 42),
            new Person("赵六1", 42),
            new Person("田七", 28)
    );

    @Test
    public void test01() {
        System.out.println("************************map**************************");
        personList.stream().map(t -> t.getName()).forEach(System.out::println);

        System.out.println("************************mapToInt**************************");
        personList.stream().mapToInt(t -> t.getAge()).forEach(System.out::println);

        System.out.println("************************mapToLong**************************");
        personList.stream().mapToLong(t -> t.getAge()).forEach(System.out::println);

        System.out.println("************************flatMap扁平化铺开**************************");
        personList.stream().filter(t -> t.getName().contains("六"))
                .map(t -> t.getName().split("六"))
                .flatMap(Arrays::stream)
                .collect(Collectors.toList())
                .forEach(System.out::println);
    }
}
